<template>
  <a-modal 
    :visible="visible"
    okText="提交" 
    cancelText="关闭"
    :title="title"
    :maskClosable="false"
    :destroyOnClose="true"
    :keyboard="false"
    width="600px"
    :confirmLoading="confirmLoading"
    @cancel="closeModal()" 
    @ok="handleSubmit">
    <a-form :form="form"  :label-col="{ span: 5 }" :wrapper-col="{ span:18 }">
      <a-form-item label="供应商分类名称">
        <a-input
        :max-length="20"
          v-decorator="['typeName',{rules: [{required: true, message: '供应商分类名称'} ]}]"
          placeholder="请输入供应商分类名称"
        />
      </a-form-item>
      <a-form-item label="排序">
        <a-input-number
          :precision="0"
          :min="0"
          v-decorator="['sort']"
        />
      </a-form-item>
     
    </a-form>
  </a-modal>
</template>
<script>
import cloneDeep from 'lodash/cloneDeep'
export default {
  name: 'type-info',
  components: {
    
  },
  props: {
    record: {
      type: Object,
      default() {
        return {}
      }
    },
    visible: {
      type: Boolean,
      default: false
    },
  },
  computed: {
    title () {
      return '新增供应商分类'
    },
    
  },
  data () {
    return {
      form: this.$form.createForm(this, { name: 'coordinated' }),
      confirmLoading: false,
      infoVisible: false,
    }
  },
  watch: {
    visible (value) {

    }
  },
  mounted () {
  },
  methods: {
    handleSubmit () {
      this.confirmLoading = true
      this.form.validateFields((err, values) => {
        if (!err) {
          values = cloneDeep(values)
          this.$post('supplier/type/add', {...values}).then(res => {
            this.confirmLoading = false
            if (res && res.returnCode === 1000) {
              this.$message.success('保存成功！')
              this.closeModal(true)
            }
          }).catch(err=> {
            this.confirmLoading = false
          })
        } else {
          this.confirmLoading = false
        }
      });
    },
    
    closeModal (freshTable) {
      this.form.resetFields()
      this.$emit('cancel', freshTable)
    },
  }
}
</script>